const express =require('express');

const noteModel = require('../db/model/noteModel');
const router = express.Router();

const verifyLogin = require('../middlewares/verifylogin');

// 页面路由
router.get('/addnote',verifyLogin,(req,res)=>{
    res.render('addnote.html')
})

router.get('/',(req,res)=>{
    res.redirect('/list');
})

router.get('/list',(req,res)=>{
    let username  = req.session.username || null;
    noteModel.find((err,data)=>{
        res.render('list.html',{data,username}); 
    }) 
})

router.get('/update',verifyLogin,(req,res)=>{

    let {id} = req.query;

    noteModel.findById(id,(err,data)=>{
        res.render('update.html',{data})
    })
})

router.get('/detail/:id',(req,res)=>{

    let id = req.params.id;

    noteModel.findById(id,(err,data)=>{
        res.render('detail.html',{data})
    })

})

router.get('/center',verifyLogin,(req,res)=>{
    res.render('center.html');
})

module.exports = router;